package com.codemonkey.lq.extend.excelverification.impl;

import com.codemonkey.lq.extend.excelverification.AbstractVerifier;
import com.codemonkey.lq.extend.excelverification.CellContext;
import com.codemonkey.lq.extend.excelverification.spi.Continuable;

/**
 * 允许为null或""
 * @author LQ
 *
 */
public final class NullableVerifier extends AbstractVerifier implements Continuable {

	private boolean isEmpty = true;

	@Override
	protected boolean doVerify(CellContext cellContext) {
		Object cellVal = cellContext.getCellVal();
		if (null == cellVal || "" == cellVal.toString()) {
			isEmpty = true;
		}

		return true;
	}

	@Override
	public String getReadableFailMsg(CellContext cellContext) {
		return "";
	}

	@Override
	public boolean isContinue(CellContext cellContext) {
		// 允许为空, 并且就是个空; 那还继续接下来的验证就没意义了 
		return (!isEmpty);
	}

}
